/**
 * @author hoang.pt
 * @version $Id$
 */

package test4.problem3;


/**
 *
 * @author hoang.pt
 */
public class Thread1 extends MyThread {

    public Thread1(Data d) {
        super(d);
    }

    /**
     * 
     */
    @Override
    public void run() {
        //get data
        this.getData();
    }

    /**
     * 
     */
    public void getData() {

        //continue for 2, 3
        int i = 0;
        while (i < 3) {
            //element 1
            //mark Data class only 1 access
            synchronized (this.d) {
                //check flag
                //--flag false then get data,
                if (!d.flag) {
                    //---change flag
                    d.flag = true;

                    //---get
                    String[] data = d.getData();
                    d.temp = data[i];

                }
            }

            try {
                Thread.sleep(1000);
            } catch (InterruptedException ex) {
            }

            i++;
        }
    }
}
